package com.ruoyi.web.controller.module.employee;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.employee.domain.EmployeeFinance;
import com.ruoyi.employee.service.IEmployeeFinanceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 店员财务信息
 * 
 * @author ruoyi
 */
@RestController
@RequestMapping("/employee/finance")
public class EmployeeFinanceController extends BaseController
{
    @Autowired
    private IEmployeeFinanceService employeeFinanceService;

    /**
     * 获取店员财务列表
     */
    @PostMapping("/employeeFinanceList")
    public TableDataInfo list(@RequestBody EmployeeFinance employeeFinance, HttpServletRequest request)
    {
        String shopId = request.getHeader("ShopId"); // 店铺id
        if(shopId != null && !shopId.equals("")){
            employeeFinance.setShopId(shopId);
        }
        startPageByPost();
        List<EmployeeFinance> list = employeeFinanceService.selectEmployeeFinanceList(employeeFinance);
        return getDataTable(list);
    }

    @Log(title = "店员财务管理 - 导出", businessType = BusinessType.EXPORT)
    @PreAuthorize("@ss.hasPermi('employee:finance:export')")
    @PostMapping("/employeeFinanceExport")
    public void export(HttpServletResponse response, EmployeeFinance user)
    {
        List<EmployeeFinance> list = employeeFinanceService.selectEmployeeFinanceList(user);
        ExcelUtil<EmployeeFinance> util = new ExcelUtil<EmployeeFinance>(EmployeeFinance.class);
        util.exportExcel(response, list, "店员财务数据");
    }
}
